// const { json } = require("express");

new Vue({
	el: '#app',
	data: function () {
		return {
			// 日历
			currentDay: 1, // 当前天
			currentMonth: 1, // 当前月
			currentYear: 1970,
			currentWeek: 0, // 一号所在的星期
			days: [], // 当月所有天数
			content: {},
			sign_days: [], // 签到日期
			is_sign: false,
			currentPlan: {},
			selectItem: '2021',
            items: [
                {id:'2021', name: '2021年05月15日'},
            ],
			selectMonth:'1',
			monthOptions:[],
			selectTypeId:'',
			selectTypeValue:'',
			allRepairTypeOptions:[
				{id:'',value:'请选择维修类型'},
				// {id:'1',value:'水电工'},
				// {id:'2',value:'煤气工'},
			],
			allRepairPeople:[
				{id:'',value:'请选择值班维修人员'},
			],
			repairPeopleStaffId:'',
			repairPeopleStaffValue:'',
			querySelectTypeId:'',
			querySelectTypeValue:'',
			beginWorkTime:'',
			bottomId:null,
			personList:'',
			isShow:-1,
			chooseNum:0,
			showSchedul:false, //显示排班弹框-用作动画
			showSchedulAll:false, //显示排班弹框

			showTime:false, //显示时间弹框-用作动画
			showTimeAll:false, //显示时间弹框
			workStartTime_1:'',
			workEndTime_1:'',
			workStartTime_2:'',
			workEndTime_2:'',
			typeTime:'00',
			userWorkId:'',
			repairType:'',
			staffId:'',
			userSubscribeId:'',
			adduserWorkId:'',
			addrepairType:'',


			typeRemove:'0',
			nowClickIndex:'', //删除的是某一个人的位置 -记录位置
			removeID:'',//删除时间段的位置
			popupRemoveConfim:false,//删除确认框
			showErrorMsg:false,
			errormsg:'',
			addTimeIndex:'',
			removeUserWorkId:'', //删除排班编号
			

			searchDate:'',
			timevalue:'',
			timevalue1:'',
			addDay:'', //哪一天的日期下面进行添加排班
			loading:false,
			host: window.location.protocol+'//'+window.location.host, //protocol--http:
			communityId:'',
			msg:'',
			errorPopup:false,
			triggerType:'',
			triggerAddRepairType:'',
			triggerAddRepair:"",
			select_time:'上班时间段',
			bstap:true,//防重复点击
			bstapBtn:true,
			removeBstap:true,
			removeBstapBtn:true,
			removeDay:'',
			localStorageCommunityId:'',

	

			mobileValue:'',
			context:'',

			
			triggerVillage:'',
			triggerVillageValue:'请选择小区',
			triggerVillageId:'',
			triggerVillageOptions:[
				{id:'',value:'请选择小区'},
			],

			triggerBuild:'',
			triggerBuildValue:'请选择楼栋',
			triggerBuildId:'',
			triggerBuildOptions:[
				{id:'',value:'请选择楼栋'},
			],

			triggerUnit:'',
			triggerUnitValue:'请选择单元',
			triggerUnitId:'',
			triggerUnitOptions:[
				{id:'',value:'请选择单元'},
			],

			triggerRoom:'',
			triggerRoomValue:'请选择房号',
			triggerRoomId:'',
			triggerRoomOptions:[
				{id:'',value:'请选择房号'},
			],


			fileFrontUrl:'',
			uploadFront:'',
			fileList:[],
			imgLength:'0',
			showUploadBtn:true,
			userSubscribeId:'',//取消预约id
			addbeginTime:'',
			addendTime:'',
			adduserId:'',
			adduserSubscribeId:'',
			requestHeaders:'',

			
		}
	},
	filters: {
		subStringThree: function (value) {
			if (!value) return ''
			return value.substring(0,3)	
		},
		checkPhone:function(value){
			// if (!value) return ''
			// if(!(/^1[3456789]d{9}$/.test(value))){ 
			// 	alert("手机号码有误，请重填");  
			// 	return false; 
			// } 
		}
	},
	created() {
		var localStorageCommunityId=JSON.parse(localStorage.getItem('hc_currentCommunityInfo'))
		if(localStorageCommunityId){
			this.communityId=localStorageCommunityId.communityId?localStorageCommunityId.communityId:this.getUrlParam("communityId");
		}else{
			this.communityId=this.getUrlParam("communityId");
		}
		this.requestHeaders=getRequestHeaders('00',this.communityId);//获取请求头
        // console.log(this.requestHeaders)
		// console.log(this.localStorageCommunityId)
	
		this.queryRepairOptions();
		this.getSign();

		let date = new Date();
		var date1=date.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
		var today =date1.split('/')[0] + '-'+this.addZero(date1.split('/')[1]) + '-' + this.addZero(date1.split('/')[2])// // 2020-01-01
		// console.log(date1,today)
		this.searchDate=today;
	},
	mounted(){
		var that=this;
	
		this.triggerType = new MobileSelect({
			trigger: '#triggerType', 
			title: '维修类型',  
			wheels: [
				{data:that.allRepairTypeOptions}
			],
			position:[0], //初始化定位
			callback:function(indexArr, data){
				// console.log(data);
				if(that.querySelectTypeValue==data[0].value){
					return
				}
				that.querySelectTypeValue=data[0].value;
				that.querySelectTypeId=data[0].id;
				that.getPersonNum();
			}
		});

		//维修类型
		this.triggerAddRepairType = new MobileSelect({
			trigger: '#triggerAddRepairType', 
			title: '维修类型',  
			wheels: [
				{data:that.allRepairTypeOptions}
			],
			position:[0], //初始化定位
			callback:function(indexArr, data){
				that.selectTypeValue=data[0].value;
				that.selectTypeId=data[0].id;
			}
		});

	
		// 具体小区
		this.triggerVillage = new MobileSelect({
			trigger: '#triggerVillage', 
			title: '请选择小区',  
			wheels: [
				{data:that.triggerVillageOptions}
			],
			position:[0], //初始化定位
			callback:function(indexArr, data){
				console.log(data);
				that.triggerVillageValue=data[0].value;
				that.triggerVillageId=data[0].id;
			    that.reset(3);
				that.queryBuild();
			},
		});

		// 楼/栋
		this.triggerBuild = new MobileSelect({
			trigger: '#triggerBuild', 
			title: '请选择楼栋',  
			wheels: [
				{data:that.triggerBuildOptions}
			],
			position:[0], //初始化定位
			callback:function(indexArr, data){
				console.log(data);
				that.triggerBuildValue=data[0].value;
				that.triggerBuildId=data[0].id;
				that.reset(2);
				that.queryUnit()
			},
		});

		// 单元
		this.triggerUnit = new MobileSelect({
			trigger: '#triggerUnit', 
			title: '请选择单元',  
			wheels: [
				{data:that.triggerUnitOptions}
			],
			position:[0], //初始化定位
			callback:function(indexArr, data){
				console.log(data);
				that.triggerUnitValue=data[0].value;
				that.triggerUnitId=data[0].id;
				that.reset(1);
				that.queryRoom();
				
			},
		});

		// 房号
		this.triggerRoom = new MobileSelect({
			trigger: '#triggerRoom', 
			title: '请选择房号',  
			wheels: [
				{data:that.triggerRoomOptions}
			],
			position:[0], //初始化定位
			callback:function(indexArr, data){
				console.log(data);
				that.triggerRoomValue=data[0].value;
				that.triggerRoomId=data[0].id;
			},
		});
	
	},
	methods: {
		// 查询维修类型
		queryRepairOptions(){
			var that=this;
			var url=this.host+'/app/repair.listRepairSettings';
		    console.log('communityId:'+this.communityId)
			var params={
				communityId:'',
				row:50,
				page:1
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询维修类型',res);
					if(res.code=='0'){
						if(res.data.length>0){
							var list=res.data;
							list.forEach(function(value,index) {
								that.allRepairTypeOptions.push({
									id:value.repairType,
									value:value.repairTypeName
								})
								
							});
							// console.log(that.allRepairTypeOptions)
							that.triggerType.updateWheel(0, that.allRepairTypeOptions);
							that.triggerAddRepairType.updateWheel(0, that.allRepairTypeOptions);
						}else{
							
						}
					}else{
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})
		},

        //查询维修类型 -根据用户查询
		queryRepairTypepeople(userId){
			var that=this;
			var url=this.host+'/app/repair.listRepairSettingsByUser';
			console.log(this.selectTypeId)
			var params={
				"staffId":userId,
			}
			$.ajax({
				url : url,
				type: 'POST',
				dataType:'json',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					console.log(res);
					if(res.code=='0'){
						if(res.data.length>0){
							var list=res.data;
							
							that.allRepairTypeOptions=[
								{id:'',value:'请选择维修类型'}
							]
							list.forEach(function(value,index) {
								that.allRepairTypeOptions.push({
									id:value.repairType,
									value:value.repairTypeName
								})
							});
							console.log(that.allRepairTypeOptions)
							that.triggerAddRepairType.updateWheel(0, that.allRepairTypeOptions);
							
						}else{
							that.allRepairTypeOptions=[
								{id:'',value:'请选择维修类型'}
							]
							that.selectTypeValue='请选择维修类型';
							that.selectTypeId='';
							console.log(that.allRepairTypeOptions)
							that.triggerAddRepairType.updateWheel(0, that.allRepairTypeOptions);
						}
					}else{
						that.allRepairTypeOptions=[
							{id:'',value:'请选择维修类型'}
						]
						that.selectTypeValue='请选择维修类型';
						that.selectTypeId='';
						that.triggerAddRepairType.updateWheel(0, that.allRepairTypeOptions);
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.allRepairTypeOptions=[
						{id:'',value:'请选择维修类型'}
					]
					that.selectTypeValue='请选择维修类型';
					that.selectTypeId='';
					that.triggerAddRepairType.updateWheel(0, that.allRepairTypeOptions);
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})
		},

		// 查询具体小区
		queryVillage(){
			var that=this;
			var url=this.host+'/callComponent/nav/getCommunitys';
			var params={
				page:1,
				row:99,
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询小区',res);
				
						if(res.communitys && res.communitys.length>0){
							var list=res.communitys;
							that.triggerVillageOptions=[
								{id:'',value:'请选择小区'}
							]
							list.forEach(function(value,index) {
								that.triggerVillageOptions.push({
									id:value.communityId,
									value:value.name
								})
							});
							// console.log(that.triggerVillage)
							that.triggerVillage.updateWheel(0, that.triggerVillageOptions);
							
					
					}else{
						that.triggerVillageOptions=[
							{id:'',value:'请选择小区'}
						]
						that.triggerVillageValue='请选择小区';
						that.triggerVillageId='';
						that.triggerVillage.updateWheel(0, that.triggerVillageOptions);
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.triggerVillageOptions=[
						{id:'',value:'请选择小区'}
					]
					that.triggerVillageValue='请选择小区';
					that.triggerVillageId='';
					that.triggerVillage.updateWheel(0, that.triggerVillageOptions);
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})

		},

		// 查询楼栋
		queryBuild(){
			var that=this;
			var url=this.host+'/callComponent/floorSelect2/list';
			var params={
				page:1,
				row:50,
				floorNum: '',
				communityId:that.triggerVillageId,
			}
			console.log(params)
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询楼栋',res);
					if(res.apiFloorDataVoList  && res.apiFloorDataVoList.length>0){
						var list=res.apiFloorDataVoList;
						that.triggerBuildOptions=[
							{id:'',value:'请选择楼栋'}
						]
						list.forEach(function(value,index) {
							that.triggerBuildOptions.push({
								id:value.floorId,
								value:value.floorName
							})
						});
						that.triggerBuild.updateWheel(0, that.triggerBuildOptions);
					}else{
						that.triggerBuildOptions=[
							{id:'',value:'请选择楼栋'}
						]
						that.triggerBuildValue='请选择楼栋';
						that.triggerBuildId='';
						that.triggerBuild.updateWheel(0, that.triggerBuildOptions);
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.triggerVillageOptions=[
						{id:'',value:'请选择楼栋'}
					]
					that.triggerBuildValue='请选择楼栋';
					that.triggerBuildId='';
					that.triggerBuild.updateWheel(0, that.triggerBuildOptions);
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})

		},

		// 查询单元
		queryUnit(){
			var that=this;
			var url=this.host+'/callComponent/unitSelect2/loadUnits';
			var params={
				page:1,
				unitNum:'',
				row:50,
				floorId: that.triggerBuildId,
				communityId:that.triggerVillageId,
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询单元',res);
					if(res && res.length>0){
						
						var list=res;
						console.log(list)
						that.triggerUnitOptions=[
							{id:'',value:'请选择单元'}
						]
						list.forEach(function(value,index) {
							that.triggerUnitOptions.push({
								id:value.unitId,
								value:value.unitNum+'单元'
							})
						});
						that.triggerUnit.updateWheel(0, that.triggerUnitOptions);
							
						
					}else{
						that.triggerUnitOptions=[
							{id:'',value:'请选择单元'}
						]
						that.triggerUnitValue='请选择单元';
						that.triggerUnitId='';
						that.triggerUnit.updateWheel(0, that.triggerUnitOptions);
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.triggerUnitOptions=[
						{id:'',value:'请选择单元'}
					]
					that.triggerUnitValue='请选择单元';
					that.triggerUnitId='';
					that.triggerUnit.updateWheel(0, that.triggerUnitOptions);
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})

		},

		// 查询房号
		queryRoom(){
			var that=this;
			var url=this.host+'/callComponent/roomSelect2/listRoom';
			var params={
				page:1,
				roomNum:'',
				row:1000,
				unitId: that.triggerUnitId,
				communityId:that.triggerVillageId,
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询房号',res);
					if(res.rooms && res.rooms.length>0){
						var list=res.rooms;
						that.triggerRoomOptions=[
							{id:'',value:'请选择房号'}
						]
						list.forEach(function(value,index) {
							that.triggerRoomOptions.push({
								id:value.roomId,
								value:value.roomNum+'室'
							})
						});
						that.triggerRoom.updateWheel(0, that.triggerRoomOptions);	
						
					}else{
						that.triggerRoomOptions=[
							{id:'',value:'请选择房号'}
						]
						that.triggerRoomValue='请选择房号';
						that.triggerRoomId='';
						that.triggerRoom.updateWheel(0, that.triggerRoomOptions);
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.triggerRoomOptions=[
						{id:'',value:'请选择房号'}
					]
					that.triggerRoomValue='请选择房号';
					that.triggerRoomId='';
					that.triggerRoom.updateWheel(0, that.triggerRoomOptions);
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})

		},
		/**
		 * 获取签到日期
		 */
		getSign () {
			let date = new Date();

			let year = date.getFullYear(); //获取当前年份
			let mon = date.getMonth() + 1; //获取当前月份
			let da = date.getDate(); //获取当前日
			if(mon <10){
				mon = '0'+mon;
			}
			if(da < 10){
				da = '0'+da;
			}

			this.startDate = year+'年'+mon+'月'+da+'日';
			this.bindDate = year+'年'+mon+'月'+da+'日';
			this.beginWorkTime = year+'-'+mon+'-'+da
			// 模拟数据
			this.initData(null);
			this.getPersonNum();
		},
		initData (cur) {
			var date;
			if (cur) { // 切换上一月、下一月
				date = new Date(cur);
			} else {
				var now = new Date(); // 此处取本机时间，应改为服务器时间
				var d = new Date(this.formatDate(now.getFullYear(), now.getMonth() + 1, 1));
				d.setDate(35); // 设置天数为35天（32~59都可以，既设置到下一个月的某一天）
				date = new Date(this.formatDate(d.getFullYear(), d.getMonth(), 1));
			}
			this.currentDay = new Date().getDate(); // 今日日期 几号
			this.currentYear = date.getFullYear(); // 当前年份
			this.currentMonth = date.getMonth() + 1; // 当前月份
			this.currentWeek = date.getDay(); // 当前月1号是星期几？ 0表示星期天
			// 当前月最后一天是星期几？ 0表示星期天
			this.nextWeek = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDay();
			var str = this.formatDate(this.currentYear, this.currentMonth, 1); // 2020/01/01
			var nextStr = new Date(date.getFullYear(), date.getMonth() + 1, 0).toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
			this.days = []; // 初始化日期
			// 设置上一个月 需显示 的最后几天  铺满一周
			for (var i = this.currentWeek; i > 0; i--) {
				var d = new Date(str);
				d.setDate(d.getDate() - i);
				var dayobject = {
					day: d,
					text:this.isText(d),
					isSign: this.isVerDate(d),
					isSigned: this.isSigned(d),
					isToday:this.isToday(d),
					isType:this.isType(d)
				}; // 用一个对象包装Date对象  以便为以后预定功能添加属性
				this.days.push(dayobject); // 将日期放入data 中的days数组 供页面渲染使用
			}
			// console.log(this.days)
			// 显示当前月的天数  第二个循环为 j<= 36- this.currentWeek，
			// 因为1号是星期六的时候当前月需显示6行，如2020年8月
			this.num = 0; //第几个月 每遇到1号加1
			for (var j = 0; j <= 36 - this.currentWeek; j++) {
				var d = new Date(str);
				d.setDate(d.getDate() + j);
				var dddd = d.getDate();
				var dayobject = {
					day: d,
					text:this.isText(d),
					isSign: this.isVerDate(d),
					isSigned: this.isSigned(d),
					isToday:this.isToday(d),
					isType:this.isType(d)
				};
				// console.log(2,d)
				if (dddd == 1) {
					this.num++
				}
				if (this.num == 2) {
					break
				}
				this.days.push(dayobject);
			}
			// console.log('当前月1号是星期' + this.currentWeek)
			// console.log('当前月最后一天是星期' + this.nextWeek)
			// 设置下一个月 需显示 的最前几天铺满一周
			for (var k = 1; k <= 6 - this.nextWeek; k++) {
				var d = new Date(nextStr);
				d.setDate(d.getDate() + k);
				var dayobject = {
					day: d,
					text:this.isText(d),
					isSign: this.isVerDate(d),
					isSigned: this.isSigned(d),
					isToday:this.isToday(d),
					isType:this.isType(d)
				}; // 用一个对象包装Date对象  以便为以后预定功能添加属性
				this.days.push(dayobject); // 将日期放入data 中的days数组 供页面渲染使用
			}
			// console.log(this.days)
		},
		/**
		 * 判断该日期是否有任务
		 * @param d
		 * @returns {boolean}
		 */
		isVerDate(d) {
			var signdays = [];
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			var t;
			var sinday=[];
			for (var i in this.sign_days) {
				signdays.push(this.sign_days[i].day);
			}
			var t = signdays.indexOf(r) == '-1' ? false : true;
			return t;
			// return signdays.includes(d.toLocaleDateString());//ie不兼容
		},
		/**
		 * 判断该日期是否有任务并且已完成
		 * @param d
		 * @returns {boolean}
		 */
		isSigned (d) {
			var signdays = [];
			for (var i in this.sign_days) {
				if (this.sign_days[i].is_sign) {
					signdays.push(this.sign_days[i].day);
				}
			}	
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			var t = signdays.indexOf(r) == '-1' ? false : true;
		
			return t;
			// return signdays.includes(d.toLocaleDateString());
		},
		isText(d){
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			for (var i in this.sign_days) {
				if (this.sign_days[i].day==r) {
					return this.sign_days[i].text;
				}
			}
		},
		isType(d){
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			for (var i in this.sign_days) {
				if (this.sign_days[i].day==r) {
					return this.sign_days[i].orgName;
				}
			}
		},
		isToday(d){
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			var now=new Date();
			var now_time=now.getFullYear()+'/'+Number(now.getMonth()+1)+'/'+now.getDate();
			if(r==now_time){
				return true;
				console.log(192,now_time)
			}
		},
		/**
		 * 上一月
		 * @param year
		 * @param month
		 */
		pickPre (year, month) {
			var d = new Date(this.formatDate(year, month, 1));
			d.setDate(0);
			this.selectMonth=d.getMonth() + 1
			this.initData(this.formatDate(d.getFullYear(), this.selectMonth, 1));
			// this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1));
		},
		/**
		 * 下一月
		 * @param year
		 * @param month
		 */
		pickNext(year, month) {
			var d = new Date(this.formatDate(year, month, 1));
			d.setDate(35);
			this.selectMonth=d.getMonth() + 1
			this.initData(this.formatDate(d.getFullYear(), this.selectMonth, 1));
			// this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1));
		},
		// 返回 类似 2020/01/01 格式的字符串
		formatDate (year, month, day) {
			month < 10 && (month = '0' + month);
			day < 10 && (day = '0' + day);
			var data = year + '/' + month + '/' + day;

			return data;
		},
		/**
		 * 点击日期查询
		 * @param index
		 */
		dayCheck(day,flag='no') {
			var currentPlan = {
				title: '',
				date: '',
				list: []
			};
			var date1=day.day.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
			currentPlan.date =date1.split('/')[1] + '月' + date1.split('/')[2] +
				'日';
			this.addDay =date1.split('/')[0] + '-'+this.addZero(date1.split('/')[1]) + '-' + this.addZero(date1.split('/')[2])
			for (var i in this.days) {
				if(this.fm(day.day)== this.fm(this.days[i].day)){
					this.$set(this.days[i], 'isChecked', 1);
					if(flag =='yes'){
						if(i>20){
							this.bottomId = 'm_second'
						}else{
							this.bottomId = 'm_first'
						}
						this.scrollTOview(this.bottomId);
					}
				}else{
					this.$set(this.days[i], 'isChecked', 0)
				}
			}
			// console.log(885,day)
			// this.searchDate=''
			this.$set(day, 'isChecked', 1);
			this.currentPlan = currentPlan
			// this.loading=true; //加载展示
            this.searchDate=this.addDay;
			// console.log(this.fm(day.day))
			this.getTodayPlace(this.fm(day.day));
			// this.choose('0')
			
		},
		addZero(n){
		 	return	n=n<10?'0'+n:n;
		},
		removeZero(n){
			return n<10?Number(n):n
	   },
		selectMonthChange(e){
			// console.log(e)
			// console.log(e.target.selectedIndex) // 选择项的index索引
			// console.log(e.target.value) // 选择项的value
			this.selectMonth=e.target.value;
			var D=new Date();
			var year=D.getFullYear()
			var d = new Date(this.formatDate(year, this.selectMonth, 1));
			d.setDate(0);
			this.initData(this.formatDate(d.getFullYear(), this.selectMonth, 1));
		},

		clickNowDay(){
			this.getSign();
		},
		/*查询最近15天预约*/
		getPersonNum(clickDay){
			var that=this;
			var today=new Date().toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			today =today.split('/')[0] + '-'+this.addZero(today.split('/')[1]) + '-' + this.addZero(today.split('/')[2])
			var url=this.host+'/app/repair.listRecently15datesRepairSchedulingList';
			// console.log(that.querySelectTypeValue,that.querySelectTypeId)
			var params={
				communityId:'',
				repairType:that.querySelectTypeId,
				beginWorkTime:'',
				days:'',
				browser:'00' //00 区分物业端业主端过来
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					// console.log(res);
					if(res.code=='0'){				
						setTimeout(function(){
							that.loading=false;
						},800)
						console.log('15天排班接口',res)
						if(res.data.length>0){
							var list=res.data;
							var listArr=[];
							list.forEach(function(item, index) {
								var day = item.formatterWorkTime.replace('-','/');
								day = day.replace('-','/');
								listArr.push({
									day: day,
									is_sign: 2,
									text:item.names,
									orgName:item.orgName
								})
							})
							that.sign_days = listArr;
							console.log(369,listArr)
						
							// console.log(clickDay)
							if(clickDay){ //新增排班成功后 定位到当前增加排班日期位置
								console.log(962,clickDay)
								var d=new Date(clickDay);
								var year=d.getFullYear();
								var month=d.getMonth()+1;
								var days=d.getDate();
								var day = {
									day:  new Date(that.formatDate(year,month, days)),
									text:that.isText(d),
									isSign: that.isVerDate(d),
									isSigned: that.isSigned(d),
									isToday:that.isToday(d)
								};
								d.setDate(0);
								that.initData(that.formatDate(year, month, 1));
								that.dayCheck(day,'yes');
							}else{
								that.initData(null);
								that.initStart();
							}	
						}else{//无数据的展示
							that.initData(null);
							that.initStart();
						}
					}else{
						that.loading=false;
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.loading=false;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		initStart() {
			// console.log(1006,this.beginWorkTime)
			var d=new Date(this.beginWorkTime);
			var year=d.getFullYear();
			var month=d.getMonth()+1;
			var days=d.getDate();
			// console.log(year)
			// console.log(month)
			// console.log(days)
			var day = {
				day:  new Date(this.formatDate(year,month, days)),
				text:this.isText(d),
				isSign: this.isVerDate(d),
				isSigned: this.isSigned(d),
				isToday:this.isToday(d)
			};
			d.setDate(0);
			this.initData(this.formatDate(year, month, 1));
			this.dayCheck(day,'yes');
		},
		fm(date){
			var date1=date.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
			return date1
		},
		scrollTOview(id){
			setTimeout(function(){
				$('#clickId').attr('href','#'+id).click();
				document.getElementById(id).scrollIntoView()
			},100)
		},
		/*查询某天预约*/
		getTodayPlace(date){
			var that = this;
			that.personList = [];
			// console.log(date)
			var d=new Date(date);
			var year=d.getFullYear();
			var month=d.getMonth()+1;
			var days=d.getDate();
			if(month <10){
				month = '0'+month;
			}
			if(days <10){
				days = '0'+days;
			}
			var daytime = year+'-'+ month+'-'+days;
			
			let url=this.host+'/app/repair.listDayRepairSchedulingListByManager';
			let params={
				communityId:'',
				workTime:daytime,
				repairType:that.querySelectTypeId
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询某天排班接口',res);
					if(res.code=='0'){
						that.loading=false;
						if(res.data.length>0){
							var list=res.data;
							that.personList = list;
						}else{

						}
					}else{
						that.loading=false;
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.loading=false;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
	
		},
		choose(index) {
			this.chooseNum = this.chooseNum +1;
			var n = this.chooseNum % 2;
			if(n == 1){
				this.chooseFlag = true
			}else{
				this.chooseFlag = false
			};
			if(this.isShow == index){
				this.isShow = '-1';
				return;
			}
			this.isShow = index
		},
		//添加排班弹框
		addSchedul(beginTime,endTime,userId,userSubscribeId){
			var that=this;
			that.selectTypeId='';
			that.selectTypeValue='维修类型';
			that.allRepairTypeOptions=[
				{id:'',value:'请选择维修类型'}
			];
			that.triggerAddRepairType.updateWheel(0, that.allRepairTypeOptions);
			that.queryRepairTypepeople(userId);
		
			that.addbeginTime=beginTime;
			that.addendTime=endTime;
			that.adduserId=userId;
			that.adduserSubscribeId=userSubscribeId;
			that.select_time='上班时间段';
			that.mobileValue='';
			that.context='';
			that.fileList=[];
			that.workStartTime_2='';
			that.workEndTime_2='';
			
		

			that.triggerVillageId='';
			that.triggerVillageValue='请选择小区';
			that.triggerCommunityId='';
			that.triggerVillageOptions=[
				{id:'',value:'请选择小区'}
			];
			that.triggerVillage.updateWheel(0, that.triggerVillageOptions);
			that.reset(3);
			that.queryVillage();

			that.showSchedulAll=true;
			setTimeout(function(){
				that.showSchedul=true;
			},50)

		},
		reset(type){
			var that=this;		
			if(type>=1){
				that.triggerRoomOptions=[
					{id:'',value:'请选择房号'}
				];
				that.triggerRoom.updateWheel(0, that.triggerRoomOptions);
				that.triggerRoomValue='请选择房号';
				that.triggerRoomId='';
				if(type>=2){
					that.triggerUnit.updateWheel(0, that.triggerUnitOptions);
					that.triggerUnitValue='请选择单元';
					that.triggerUnitId='';
					that.triggerUnitOptions=[
						{id:'',value:'请选择单元'}
					];
					if(type>=3){
						that.triggerBuildOptions=[
							{id:'',value:'请选择楼栋'}
						];
						that.triggerBuild.updateWheel(0, that.triggerBuildOptions);
						that.triggerBuildValue='请选择楼栋';
						that.triggerBuildId='';
					}	
				}
				
			}
		},
		//关闭添加排班弹框
		closePopup(){
			var that=this;
			this.showSchedul=false;
			setTimeout(function(){
				that.showSchedulAll=false;
			},350)
		},
		//上班时间段选择弹框
		timeSelect(type,index,userWorkId,repairType){
			this.typeTime=type;//00添加时间段   01新增排班-添加时间段 
			if(this.typeTime=='00'){
				this.addTimeIndex=index; //获取哪一个的添加时间段
				this.userWorkId=userWorkId; //排班编号
				this.repairType=repairType;//维修类型
				// console.log(this.userWorkId,this.repairType)
			}
			this.showTime=true;
			this.showTimeAll=true;
		},
		//关闭上班时间段弹框
		cancalTime(){
			var that=this;
			this.showTime=false;
			setTimeout(function(){
				that.showTimeAll=false;
			},400)
		},
		//确认 上班时间段弹框
		confimTime(){
			var that=this;
			if(this.typeTime=='00'){
				if(!this.workStartTime_1){
					this.showErrorMsg=true;
					this.errormsg='上班开始时间不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)	
					return;
				}
				if(!this.workEndTime_1){
					this.showErrorMsg=true;
					this.errormsg='下班结束时间不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return;
				}
				if(this.timeComparison(this.workStartTime_1,this.workEndTime_1)){
					this.showErrorMsg=true;
					this.errormsg='上班开始时间不能大于或等于下班结束时间';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return;
				}
				if(this.bstap==false){
					return
				}
				//添加时间端段接口
				let url=this.host+'/app/repair.addRepairWorkTimeByManager';
				let params={
					"communityId":this.communityId,
					"workTime":this.addDay,
					"repairType":this.repairType,
					"userWorkId":this.userWorkId,
					"beginTime":this.addDay+' '+this.workStartTime_1+':00',
					"endTime":this.addDay+' '+this.workEndTime_1+':00',
					"staffId":this.staffId
				}
				this.bstap=false;
				$.ajax({
					url : url,
					type: 'POST',
					dataType:'json',
					contentType: 'text/plain',
					headers:that.requestHeaders,
					data: JSON.stringify(params),
					success : function (res){
						that.bstap=true;
						if(res.code=='200'){
							that.personList[that.addTimeIndex].details.push({
								"communityId":that.communityId,
								"workTime":that.addDay,
								"repairType":that.repairType,
								"userWorkId":that.userWorkId,
								"beginTime":that.workStartTime_1,
								"endTime":that.workEndTime_1,
								"staffId":that.staffId
							})
						
							that.showErrorMsg=true;
							that.workStartTime_1='';
							that.workEndTime_1='';
							that.errormsg='新增成功！';
							var day =that.addDay.split('-')[0] + '/'+that.removeZero(that.addDay.split('-')[1]) + '/' + that.removeZero(that.addDay.split('-')[2])
							that.getTodayPlace(day);
							// console.log(day)
							setTimeout(function(){
								that.showErrorMsg=false;
							},1000)
							that.showTime=false;
							setTimeout(function(){
								that.showTimeAll=false;
							},400);
						}else{
							console.log(res)
							that.errorPopup=true;
							that.msg=res.msg
						}
					},
					error:function(res){
						that.bstap=true;
						console.log(res)
						that.errorPopup=true;
						that.msg=res.responseText?res.responseText:'请求超时'
					}
				})
			}else{
				if(!this.workStartTime_2){
					this.showErrorMsg=true;
					this.errormsg='上班开始时间不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)	
					return;
				}
				if(!this.workEndTime_2){
					this.showErrorMsg=true;
					this.errormsg='下班结束时间不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return;
				}
				if(this.timeComparison(this.workStartTime_2,this.workEndTime_2)){
					this.showErrorMsg=true;
					this.errormsg='上班开始时间不能大于或等于下班结束时间';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return;
				}
				this.showTime=false;
				this.select_time=this.workStartTime_2+"~"+this.workEndTime_2
				setTimeout(function(){
					that.showTimeAll=false;
				},400);
				// console.log(this.workStartTime_2,this.workEndTime_2)
			}
		},
		showRemoveConfim(userSubscribeId){
			this.popupRemoveConfim=true;
			this.userSubscribeId=userSubscribeId;
		},
		//确认取消预约
		removeConfim(){
			let that=this;
			let url=this.host+'/app/repair.cancelOwnerRepairAppointmentByManager';
			let params={
				"userSubscribeId":this.userSubscribeId,
			}
			if(that.removeBstap==false){
				return;
			}
			that.removeBstap=false
			console.log(params)
			$.ajax({
				url : url,
				type: 'POST',
				dataType:'json',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					console.log('取消预约接口',res);
					that.removeBstap=true
					if(res.code=='200'){
						that.showErrorMsg=true;
						that.errormsg='取消预约成功！';
						setTimeout(function(){
							that.showErrorMsg=false;
						},1500)
						that.popupRemoveConfim=false;
						that.popupRemoveConfim=false;
						that.getPersonNum(that.removeDay);
						return;	
					}else{
						that.popupRemoveConfim=false;
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.popupRemoveConfim=false;
					that.removeBstap=true
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
			
		},
		//保存按钮 --排班时间保存
		submitSave(){},
		//维修预约提交接口
		submit_add(){
			let that=this;
			if(that.bstapBtn==false){
				return;
			}
			let url=that.host+'/app/repair.saveOwnerRepairAppointmentByManager';
			if(that.triggerVillageId==''){
				that.showErrorMsg=true;
				that.errormsg='小区名称不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}
			else if(that.triggerBuildId==''){
				that.showErrorMsg=true;
				that.errormsg='楼栋不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}
			else if(that.triggerUnitId==''){
				that.showErrorMsg=true;
				that.errormsg='单元不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}else if(that.triggerRoomId==''){
				that.showErrorMsg=true;
				that.errormsg='房号不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}else if(that.selectTypeId==''){
				that.showErrorMsg=true;
				that.errormsg='维修类型不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}else if(that.mobileValue==''){
				that.showErrorMsg=true;
				that.errormsg='预约人手机号不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}else if(that.context==''){
				that.showErrorMsg=true;
				that.errormsg='报修内容说明不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}
			if(that.mobileValue){
				var regPhone = /^1[3456789]{1}\d{9}$/
				if(!regPhone.test(that.mobileValue)){ 
					that.showErrorMsg=true;
					that.errormsg='请输入正确的手机格式';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return false; 
				}
			}
			var fileId=[];
			that.fileList.forEach(function(value){
				fileId.push(value.fileIds)
			});
			
			let params={
				"userId":that.adduserId,
				"repairType":that.selectTypeId,
				"appointmentTime":that.addDay,
				// "appointmentTime":that.addDay+' '+ that.addbeginTime+"~"+that.addendTime,
				"roomId":that.triggerRoomId,
				"mobile":that.mobileValue,
				"photoIds":fileId,
				"repairObjId":'',
				"repairObjType":'',
				"repairObjName":that.triggerBuildValue+that.triggerUnitValue+that.triggerRoomValue,
				"context":that.context,
				'userSubscribeId':that.adduserSubscribeId,
				'communityId':that.triggerVillageId,
			}



			that.bstapBtn=false;
			console.log(params)
			$.ajax({
				url : url,
				type: 'POST',
				dataType:'json',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					console.log('排班提交接口',res);
					that.bstapBtn=true;
					if(res.code=='200'){
						that.showErrorMsg=true;
						that.errormsg='新增成功！';
                        // console.log(that.selectTypeId,that.selectTypeValue)
						that.getPersonNum(that.addDay);
						that.repairPeopleStaffValue='请选择值班维修人员';
						that.repairPeopleStaffId='';
						that.selectTypeValue='维修类型';
						that.selectTypeId='';
						// console.log(day)
						setTimeout(function(){
							that.showErrorMsg=false;
						},1500)
						that.showSchedul=false;
						setTimeout(function(){
							that.showSchedulAll=false;
						},350)
						return;	
					}else{
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.bstapBtn=true;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		changeDateValue(){
			console.log(this.searchDate)
			var d=new Date(this.searchDate);
			var year=d.getFullYear();
			var month=d.getMonth()+1;
			var days=d.getDate();
			var day = {
				day:  new Date(this.formatDate(year,month, days)),
				text:this.isText(d),
				isSign: this.isVerDate(d),
				isSigned: this.isSigned(d),
				isToday:this.isToday(d)
			};
			d.setDate(0);
			this.initData(this.formatDate(year, month, 1));
			this.dayCheck(day,'yes');
		},
		timeBlur(){
			var that=this;	
			if(this.timevalue>0 && this.timevalue<1440){
				this.timevalue=this.getInteger(this.timevalue)
			}else{
				this.showErrorMsg=true;
				this.errormsg='时间间隔为整数且不可超过1440(分钟)';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				this.timevalue='';
				return;
			}

		},
		//获取小数点前面的数字
		getInteger(num){
			var val=num.toString();
			if(val.indexOf('.')==-1){
				return val;
			}else{
				return val.substring(0,val.indexOf('.'))
			}
		},
		//时分比较
		timeComparison(start,end){
			//分割开始时间的时
			let kaiShi = start.split(":")[0];
			//分割开始时间的分
			let kaiFen = start.split(":")[1];
			//分割结束时间的时
			let jieShi = end.split(":")[0];
			//分割结束时间的分
			let jieFen = end.split(":")[1];
			//判断两者的时
			if(kaiShi < jieShi){
				return false;
			}else if(kaiShi == jieShi){
				//如果等于的话就判断两者的分
				if(kaiFen < jieFen){
					return false;
				}else{
					return true;
				}
			}else{
				return true;
			}
		},
		getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if (r != null) return unescape(r[2]);
			return null; //返回参数值
	  
		},

		// 图片上传
		clickUploadImg(){
			this.$refs.uploadFile.dispatchEvent(new MouseEvent('click'))
		},
		// 图片上传
		upload (event) {
			let files = event.target.files || event.dataTransfer.files
			let file=files[0];
			var url='';
			var that=this;
			// var reader = new FileReader();
			// reader.readAsDataURL(file);
			console.log(file)
			if(file.size < 1024 * 1024 * 1){//小于1M不压缩图片
			  this.notcompressImg(file,url)
			}else{
				if( file.size > 1024 * 1024 * 5 ){//大于5M提示
					that.showErrorMsg=true;
					that.errormsg='图片大小请控制在5MB以内';
					that.$refs.uploadFile.value=''
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)	
				}else{
					this.compressImg(file,url)
				}
			}
		  },
		// 图片不压缩
		notcompressImg(file,url){
			let that = this;
			var reader = new FileReader();
			reader.readAsDataURL(file);
			reader.onload = function (e) {
				url=this.result.substring(this.result.indexOf(',')+1);
				// console.log("不压缩img："+url)
				that.fileFrontUrl='data:image/png;base64,'+url;
				that.uploadFront=url; 
				that.getFileUpload(that.fileFrontUrl)
			}
		},
		  
		// 图片压缩方法
		compressImg(file,url){
		// 注意这里this作用域的问题
			let that = this;
			var reader = new FileReader();
			reader.readAsDataURL(file);
			reader.onload = function(e) {
				var bdata = this.result;
				// 这里quality的范围是（0-1）
				var quality = 0.1;
				var canvas = document.createElement("canvas");
				var ctx = canvas.getContext("2d");
				var img = new Image();
				img.src = bdata;
				img.onload =function() {
					var width = img.width;
					canvas.width = width;
					canvas.height = width * (img.height / img.width);
					ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
					var data = canvas.toDataURL("image/jpeg",quality);
					url=data.substring(data.indexOf(',')+1);
					// console.log("压缩img："+url)
					that.fileFrontUrl='data:image/jpeg;base64,'+url;
					that.uploadFront=url;
					that.getFileUpload(that.fileFrontUrl)
				}
			};
		},
		//图片上传接口
		getFileUpload(file) {
			let that=this;
			var filelist=[]
			filelist.push(file)
			// // that.fileFrontUrl=file.name;
			var url=this.host+'/app/uploadFiles';
			var params={
				files:filelist,
				relTypeCd:'84003'
			}
			that.loading=true;
			setInterval(function(){
				that.loading=false;
			},1000)
			$.ajax({
				url : url,
				type: 'POST',
				dataType:'json',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					console.log('上传图片',res);
					that.bstapBtn=true;
					if(res.code=='200'){
						var fileIds=res.fileIds[0];
						
						that.fileList.push({
							fileFrontUrl:file,
							fileIds:fileIds
						})
						console.log(that.fileList)
						var imglength=that.fileList.length;
						that.imgLength=imglength
						if(imglength>=3){
							that.showUploadBtn=false
						}else{
							that.showUploadBtn=true
						}
						that.showErrorMsg=true;
						that.errormsg='上传成功！';
						setTimeout(function(){
							that.showErrorMsg=false;
						},1500)
						that.loading=false;
		
						return;	
					}else{
						that.loading=false
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.loading=false
					that.bstapBtn=true;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		removeUpload(item){	
			for(let i=0;i<this.fileList.length;i++){
				if(this.fileList[i]==item){
					this.fileList.splice(i,1)
				}
			}
			var that=this;
			var imglength=that.fileList.length;
			that.imgLength=imglength
			if(imglength>=3){
				that.showUploadBtn=false
			}else{
				that.showUploadBtn=true
			}
		},
			  
		//添加值班人员先判断维修类型是否已选
		addPeople(){
			var that=this;
			this.showErrorMsg=true;
			this.errormsg='请先选择维修类型';
			setTimeout(function(){
				that.showErrorMsg=false;
			},1500)
			return;
		}
	}
});